import { ref } from 'vue'
import { adapter, request } from '@/request'
import type { RequestWrapper } from '@/core/interfaces/common'
import { userDetail } from '@/core/api/user'

export interface getBwJumpType {
  id: number
  username: string
  fullName: string
  password: string
  enabled: number
  type: number
  deptId?: any
  customerId?: any
  employeeCode: string
  mobile: string
  email: string
  inductionTime: string
  proxyId: number
  department?: any
  groupName?: any
  version: number
  isDelete: boolean
  createUserName: string
  createUserId: number
  createTime: string
  updateUserName: string
  updateUserId: number
  updateTime: string
  pwd: string
}
interface params {
  id: number
}
export default function userDetailFn() {
  const service = adapter<RequestWrapper<getBwJumpType>>(request)
  const loading = ref(false)
  const response = ref<getBwJumpType>()

  const fetch = (params: Partial<params>) => {
    const { url, method } = userDetail()
    loading.value = true

    return service({
      config: {
        url,
        method,
        params
      },
      callback: (res) => {
        response.value = res.data.data
      },
      error: (err) => {
        console.log(err)
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [response, fetch, loading] as const
}
